<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>项目新增</title>
<link rel="stylesheet" href="../../css/ecp.min.css" />
<link rel="stylesheet" href="../../js/webuploader/webuploader.css" />
<script src="../../js/lib.min.js"></script>
<script src="../../js/requirejsConfigObj.js"></script>
<script src="../../js/requirejs/2.1.17.js"></script>
<script src="../../js/common.min.js"></script>

<style  type="text/css">
    .check_error{color:red;border-color:red;}
    .width130{width:460px;height: 25px;}
    .width120{width:120px;height: 25px;}
    .width60{width:70px;height: 25px;margin-right: 10px;}
    .errText{margin-left:10px;visibility:hidden; }
    .page_title_nm{font-size: 16px;font-weight: initial;margin: 5px 0px 0px 10px;}
    /* #table_tbody .error{padding-left:0} */
.search-title{
	border-top-left-radius:5px;
	border-top-right-radius: 5px;
	padding: 10px;
	font-weight: bolder;
}

.result-title{color:black;position: relative;height: 25px;}
.result-title a {
	position: absolute;
	right: 18px;
	top: 8px;
	padding: 2px 8px;
	border: 1px solid #4A81C4;
	background: #3A8BE0;
	color: #fff;
	border-radius: 3px;
}
.pro-tab-list{
	border-collapse:collapse;
}
  
</style>    
</head>
<body> 
  <div id="showMsg" class="project"></div> 
  <div class="project-dialog"> 
   <form id="formItem" name="formItem" style="width: 100%;"> 
     <div>
      <table class="form_table" width="95%"> 
       <tbody id="table_tbody">
       <tr>
            <td width="130">
                 <label class="description"> <span class="fn-high">*</span>姓名</label>
            </td>
            <td width="260" colspan="3">
                <input type="text" class="inputWidth width130" maxlength="100" name="personNm" id="personNm"/>                   
            </td>            
       </tr>
       <tr>
            <td width="130">
                 <label class="description"> 类型</label>
            </td>
            <td width="260" colspan="3">
            	<select class="inputSelect inputWidth" id="personTypeCd" name="personTypeCd">
					<option value="">--请选择--</option>
					<option value="1001">董事长</option>
					<option value="1002">总经理</option>
					<option value="1003">地区经理</option>
					<option value="1004">员工</option>
				 </select>   
            </td>            
       </tr>
       <tr>
            <td width="130">
                 <label class="description"> 电话</label>
            </td>
            <td width="260" colspan="3">
                <input type="text" class="inputWidth width130" maxlength="100" name="personTelnum" id="personTelnum" onblur="checkTel(this);"/><span class="check_error errText">请填写正确的手机号码</span>                 
            </td>            
       </tr>
       <tr>
            <td width="130">
                 <label class="description"> 身份证</label>
            </td>
            <td width="260" colspan="3">
                <input type="text" class="inputWidth width130" maxlength="100" name="credNum" id="credNum" onblur="checkCred(this);"/><span class="check_error errText">请填写正确的身份证号码</span>                     
            </td>            
       </tr>
       <tr>
            <td>
                 <label class="description"> 地址</label>
            </td>
            <td>
                <input type="text" class="inputWidth width130" maxlength="200" name="personAddr" id="personAddr"/>   
            </td>
        </tr> 
        <tr>
            <td>
                 <label class="description"> 现居住地址</label>
            </td>
            <td>
                <input type="text" class="inputWidth width130" maxlength="200" name="nowAddr" id="nowAddr"/>   
            </td>
        </tr>  
        <tr>
            <td>
                 <label class="description"> 头像照片</label>
            </td>
            <td>
                 <div>
					<input type="hidden" id="fileName" name="fileName"/>
                    <input type="hidden" id="filePaths" name="filePaths"/>
                	<div id="fileList" class="uploader-list"></div>
                    <div class="imgPick" id="filePicker">选择图片</div>
                    <div class="ui-textcolorml " >建议尺寸为225*225像素,大小不超过1M</div>
				</div>    
            </td>
        </tr>        
        <tr>
           <td>
               <label class="description">简介</label>
           </td>
           <td colspan="3">
               <textarea type="text" name="personDesc" id="personDesc" class="form-textarea"  placeholder="请输入500字以内" style="width: 700px;height: 130px;resize:none ;" onblur="true" maxlength="500"></textarea>
           </td>
       </tr>
       <tr>
	        <td>
	            <label class="description"> <span class="fn-high">*</span>详细介绍</label>
	        </td>
	        <td>
	            <textarea type="text" name="personCntt" id="personCntt" style="width:650px;height:400px;visibility:hidden;"></textarea>
	        </td>
       </tr>       
       </tbody> 
      </table> 
      <hr />
     <div class="formBtnArea"> 
      <table width="100%"> 
       <tbody>
        <tr> 
         <td> 
          <div class="normalBtnArea fn-center"> 
           <input type="hidden" id="hideDataRoute" name="hideDataRoute" value=""/>
           <a class="normalBtn BGblue largeBtn" href="javascript:;" id="J_save" attr_save_type="1" onclick="save()">保存</a> 
           <a href="javascript:;" class="BGblue largeBtn" id="J_cancel" onclick="cancleConfirm()"><span>返回</span></a> 
          </div> 
          </td> 
        </tr> 
       </tbody>
      </table> 
     </div> 
    </div> 
   </form> 
  </div>
 </body>

<script src="../../js/kindeditor/kindeditor-all.js"></script>
<script src="../../js/webuploader/webuploader.js"></script>
<script src="../../js/self_fun.js"></script>
<script type="text/javascript">

$(function(){
	editor = KindEditor.create('textarea[name="personCntt"]', {
        allowFileManager: true,
        uploadJson:"/upLoad",
        afterUpload : function(url, data, name) { //上传文件后执行的回调函数，必须为3个参数
            if(name=="image" || name=="multiimage"){ //单个和批量上传图片时
                var img = new Image(); img.src = url;
                img.onload = function(){ //图片必须加载完成才能获取尺寸
                	if(img.width>500) editor.html(editor.html().replace('<img src="' + url + '"','<img src="' + url + '" width="500"'))
                }
            }
        },
        items: [
			'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste',
			'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter', 'justifyright',
			'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript',
			'superscript', 'clearhtml', 'quickformat', 'selectall', '|', 'fullscreen', '/',
			'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold',
			'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|', 'image',
			'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak',
			'anchor', 'link', 'unlink', '|', 'about'
        ]
      });
	initWeb("#fileList","#filePicker",'#filePaths');
});
function  qryOpAndRaVal(){
    var str = "5000$5023";
    var param={queryType:str};
    Util.ajax.postJsonSync("/home", param, function(json,status){
              alert(json.aaaa);           
    });
}
function imgFileOpt(){
	var reader = new FileReader();
    var AllowImgFileSize = 2100000; //上传图片最大值(单位字节)（ 2 M = 2097152 B ）超过2M上传失败
    var file = $("#browsefile")[0].files[0];
    var imgUrlBase64;
    if (file) {
        //将文件以Data URL形式读入页面  
        imgUrlBase64 = reader.readAsDataURL(file);
        reader.onload = function (e) {
          //var ImgFileSize = reader.result.substring(reader.result.indexOf(",") + 1).length;//截取base64码部分（可选可不选，需要与后台沟通）
          if (AllowImgFileSize != 0 && AllowImgFileSize < reader.result.length) {
        	  top.Util.dialog.tips( '上传失败，请上传不大于2M的图片！');
                return;
            }else{
                //执行上传操作
                html = '<img src="'+reader.result+'" width="200" height="200"/>';
                $("#fileList").html(html);
                $("#filepath").val(reader.result);
                setHeight();
            }
        }
     }         
}	 
function save(){  
	var personNm = $("#personNm").val();
   	if(isDataNull(personNm)){
   		top.Util.dialog.tips('请填写姓名！');
   	 return;
   	}
	var c = "";
   	ntcCnttContent = editor.html();
   	if(ntcCnttContent=='' ||ntcCnttContent==null){
    	 top.Util.dialog.tips('请填写个人介绍！');
    	 return;
    }  
   	var personDesc = $("#personDesc").val();
   	var credNum = $("#credNum").val();
   	var personAddr = $("#personAddr").val();
   	var personTelnum = $("#personTelnum").val();
   	if(!isDataNull(personTelnum) && !checkTelnum(personTelnum)){
   		top.Util.dialog.tips('请填写正确的手机号！');
   	 return;
   	}
   	if(!isDataNull(credNum) && !checkCredNum(credNum)){
   		top.Util.dialog.tips('请填写正确的身份证号！');
   	 return;
   	}
   	var personTypeCd = $("#personTypeCd").val();
   	var nowAddr = $("#nowAddr").val();
   	var filepath = $("#filepath").val();
   	var filePaths = $("#filePaths").val();
   	var param = {
   			'personNm':personNm,
   			'personAddr':personAddr,
   			'personTelnum':personTelnum,
   			'personTypeCd':personTypeCd,
   			'credNum':credNum,
   			'personDesc':personDesc,
   			'personCntt':ntcCnttContent,
   			'nowAddr':nowAddr,
   			'filePaths':filePaths,
   			'headFile':filepath
   	}
	Util.ajax.postJsonSync("/addPersonInfo",param,function(json,status){
           if(status){
        	   if(json.bean.rtnCd == "00"){ 
                   window.parent.inint();
                  window.parent.closeIframeDialog();                  
               }else{              
                   window.parent.setTip("保存失败",top,2000);
               }
           }else{
               var rtnMsg = json.bean.rtnMsg ? json.bean.rtnMsg : "";
               Util.dialog.tips("保存失败,请重试!!"+rtnMsg);
           }
     }); 
}
function checkTel(_this){
	var str = $(_this).val();
	if(!isDataNull(str)){
		if(!checkTelnum(str)){
			$(_this).parent().find('span').css('visibility','visible');
		}else{
			$(_this).parent().find('span').css('visibility','hidden');
		}
	}else{
		$(_this).parent().find('span').css('visibility','hidden');
	}
}
function checkCred(_this){
	var str = $(_this).val();
	if(!isDataNull(str)){
		if(!checkCredNum(str)){
			$(_this).parent().find('span').css('visibility','visible');
		}else{
			$(_this).parent().find('span').css('visibility','hidden');
		}
	}else{
		$(_this).parent().find('span').css('visibility','hidden');
	}
}
	//取消确认弹框
	function cancleConfirm(){
		//window.location.href = "newProjEstabMana.html?";
		window.parent.closeIframeDialog();
	};
  
    //表单校验
    var validatePoorHouseInfo = $("#formItem").validate({
    	rules:{
    		companyNm:{
        		required:true,
        	},
        	companyTelnum:{
        		required:true,
        	},
        	companyAddr:{
        		required:true,
            }
        },
        messages:{
        	companyNm:{
        		required:"必填",
            },
            companyTelnum:{
            	required:"必填",
            },
            companyAddr:{
            	required:"必填",
            }
        },
        showErrors:function(){
            this.defaultShowErrors();
        }
    });
    jQuery.validator.addMethod("checkNumber",function(value,element) { 
        var regUrl = /^[1-9]\d{0,14}$/;// /^\d{0,15}$/;
        return this.optional(element) || regUrl.test(value);
    }, "请输入正整数");
    
    jQuery.validator.addMethod("checkLittleNumber",function(value,element) { 
    	var regUrl = /^\d{0,10}(\.\d{1,4})?$/;
        return this.optional(element) || regUrl.test(value);
    }, "保留4位小数");
    
    function checkNumberDecimals(num){
    	var regx = /^\d{0,20}(\.\d{1,2})?$/;
    	if(regx.test(num)){
    		return true;
    	}else{
    		return false;
    	}
    }
  	//账号校验  请正确填写银行账号
    function checkAcctNum(num){
    	var regUrl = /^\+?[1-9][0-9]*$/;
   	  	if(regUrl.test(num) && num.length >= 14 && num.length <= 19){
   		  	return true;
   	  	}else{
   		  	return false;
   	  	}
    }
    function checkTotalInvest(num){
    	var regx = /^\d{0,7}(\.\d{1,4})?$/;
    	if(regx.test(num)){
    		return true;
    	}else{
    		return false;
    	}
    }
    function checkTotalNum(num){
    	var regx = /^\d+$/;
    	if(regx.test(num)){
    		return true;
    	}else{
    		return false;
    	}
    } 
 
  //图片上传
    function initWeb(fileId,pickerId,picPaths){
  	  var $ = jQuery,
       $list = $(fileId),
  	// 优化retina, 在retina下这个值是2
  	      ratio = window.devicePixelRatio || 1,
  	
  	// 缩略图大小
  	      thumbnailWidth = 100 * ratio,
  	      thumbnailHeight = 100 * ratio,
  	// Web Uploader实例
  	 uploader;
  	 var familyPicUrls = '';
  	 var allPicUrls = '';//包含所有前端页面预览过的图片的地址
  	// 初始化Web Uploader
  	uploader = WebUploader.create({
  	  // 自动上传。
  	  auto: true,
  	
  	  // 图片上传前进行压缩
  	  compress: false,
  	  duplicate :true,  
  	  // swf文件路径
  	  swf:  '../../js/webuploader/Uploader.swf',
  	  //server:'../../front/sh/info!fanxianUploadPicImg?uid=s001',
  	  server:'/uploadPicFile',
  	  // 选择文件的按钮。可选。
  	  // 内部根据当前运行是创建，可能是input元素，也可能是flash.
  	  pick: {id:pickerId,multiple:false},
  	  // 只允许选择文件，可选。
  	  accept: {
  	      title: 'Images',
  	      extensions: 'gif,jpg,jpeg,bmp,png',
  	      mimeTypes: 'image/jpg,image/jpeg,image/png,image/bmp,image/gif'
  	  },
  	   fileVal: "uploadfile",
  	   fileSingleSizeLimit:3145728
  	});
  	
  	         
  	//图片加入队列前,判断图片大小
  	uploader.on('beforeFileQueued',function(file){
  	    var picUpload = $(fileId).find(".file-item");
  	    if(picUpload.length >= 1){
  	      Util.dialog.tips("最多只能上传1张照片,其他图片请上传到详细介绍",top,1000);
  	      return false;
  	    }  
  	    if(file.size > 3145728){
  	        Util.dialog.tips("图片大于3M，请重新选择",top,1000);
  	    }
  	    var injStra = ["script", "mid", "master", "truncate ", "insert ", "select ",
                         "delete ", "update ", "declare", "iframe", "onreadystatechange", "alert", "atestu", "xss",
                         ";","'","\"","<",">","(",")",",","\\","svg","confirm","prompt","onload","onmouseover",
                         "onfocus","onerror","and ","or ","union ","where ","limit ","group ","by ","hex","substr",
                         "\r","\n"];
          var injFileName = file.name.toLowerCase();
          var flag = 1;
          for (var i = 0; i<injStra.length; i++) {
              if (injFileName.indexOf(injStra[i])>=0) {              
                  flag =2;
              }
          }
          if(flag == 2){
              Util.dialog.tips("图片名称含有特殊字符，请修改");                
              return false;
          }
  	    
  	})
  	uploader.on( 'uploadStart', function( file ) {});
  	// 当有文件添加进来的时候
  	uploader.on( 'fileQueued', function( file ) {  
 		 var $li = $(
 		          '<div id="' + file.id + '" class="file-item thumbnail">' +
 		          '<img>' +
 		          '<div class="delpic"><span id=""  style="color: #08c;visibility:hidden;" onclick="delPic(this)">删除图片</span></div><div class="excelProcess" style="visibility:hidden;"></div></div>'
 		  ),
 		  $img = $li.find('img');
 		  $list.append( $li ); 
  	$(".delpic").find('span').on('click',function(){	    
  		var _this=$(this);
  	      var picId=_this.attr("id");//在图片上传时已修改为图片地址
  	      var picUrls = $(picPaths).val();  
  	      var regx = new RegExp('\\,?'+picId);
  	      var path = picUrls.replace(regx, "");
  	      if(path.indexOf(',') === 0){path = path.substring(1);}
  	      $(picPaths).val(path);
  	      _this.parents(".file-item").remove();
  	});
  	// 创建缩略图
  	uploader.makeThumb( file, function( error, src ) {
  	  if ( error ) {
  	      $img.replaceWith('<span>不能预览</span>');
  	      return;
  	  }   
  	  $img.attr( 'src', src );
  	}, 60, 60 );	
  	});
  	
  	// 文件上传过程中创建进度条实时显示。
  	uploader.on( 'uploadProgress', function( file, percentage ) {
  	  $('#'+file.id).find('.excelProcess').css('visibility','visible');
  	  $('#'+file.id).find('.excelProcess').html('<p class="progress" style="width:'+percentage * 99+'%"></p><span>'+(percentage.toFixed(2)* 99)+'%</span>');
  	});
  	// 文件上传成功，给item添加成功class, 用样式标记上传成功。
  	uploader.on( 'uploadSuccess', function(file, data) {
  	  var picUrl = data.picUrl;
  	  //var imgName = data.fileName;
  	  familyPicUrls = $(picPaths).val();
  	  familyPicUrls += ","+picUrl;
  	  if(familyPicUrls.indexOf(',') === 0){familyPicUrls = familyPicUrls.substring(1);}
  	  $('#' + file.id).find(".delpic span").attr("id", picUrl);
  	  $(picPaths).val(familyPicUrls);//最终上传图片
  	  $( '#'+file.id ).addClass('upload-state-done');
  	  $('#'+file.id).find('.excelProcess').css('visibility','visible');
  	  if(isDataNull(picUrl)){
  		  $('#'+file.id).find('.excelProcess').html('上传失败');
  	  }else{
  	 	 $('#'+file.id).find('.excelProcess').html('上传成功');
  	  }
  	  $('#'+file.id).find(".delpic span").css('visibility','visible');
  	});
  	// 文件上传失败，显示上传出错。
  	uploader.on( 'uploadError', function( file ) {
  	  var $li = $( '#'+file.id ),
  	          $error = $li.find('div.error');
  	  if ( !$error.length ) {
  	      $error = $('<div class="error"></div>').appendTo( $li );
  	  }
  	  if(uploader.getFiles('queued','progress').length == 0){
  		  $("J_save").css('visibility','visible');
  	  }
  	  $("#"+file.id).remove();
  	});
  	
  	// 完成上传完了，成功或者失败，先删除进度条。
  	uploader.on( 'uploadComplete', function( file ) {
  	
  	});
  	
  	//解决ie9下上传png无法到后台的问题
  	if(navigator.userAgent.indexOf("MSIE")>0 && navigator.userAgent.indexOf("MSIE 9.0")>0){   
		  	var setHeader = function(object, data, headers) {
		  	      headers['Access-Control-Allow-Origin'] = '*';
		  	      headers['Access-Control-Request-Headers'] = 'content-type';
		  	      headers['Access-Control-Request-Method'] = 'POST';
		  	  }
		  	uploader.on('uploadBeforeSend ', setHeader);
	  	}
    }
function setHeight(){
    window.parent.setIframeHeight();
}
</script>
</body>
</html>